Source for file SC_Fpdf.php

Documentation is available at SC_Fpdf.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24. /*----------------------------------------------------------------------
  25.  * [名称] GC_Fpdf
  26.  * [概要] pdfファイルを表示する。
  27.  *----------------------------------------------------------------------
  28.  */
  29.  
  30. require(DATA_PATH . 'pdf/japanese.php');
  31. define('PDF_TEMPLATE_DIR', DATA_PATH . 'pdf/');
  32.  
  33. class SC_Fpdf {
  34.       
  35.     function SC_Fpdf($download, $title, $tpl_pdf = "template_nouhin01.pdf") {
  36.         // デフォルトの設定
  37.         $this->tpl_pdf = PDF_TEMPLATE_DIR . $tpl_pdf;  // テンプレートファイル
  38.         $this->pdf_download = $download;      // PDFのダウンロード形式(0:表示、1:ダウンロード)
  39.         $this->tpl_title = $title;
  40.         $this->tpl_dispmode = "real";      // 表示モード
  41.         $masterData = new SC_DB_MasterData_Ex();
  42.         $this->arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank"));
  43.         $this->width_cell = array(110.3,12,21.7,24.5);
  44.  
  45.         $this->label_cell[] = $this->sjis_conv("商品名 / 商品コード / [ 規格 ]");
  46.         $this->label_cell[] = $this->sjis_conv("数量");
  47.         $this->label_cell[] = $this->sjis_conv("単価");
  48.         $this->label_cell[] = $this->sjis_conv("金額(税込)");
  49.  
  50.         $this->arrMessage = array(
  51.           'このたびはお買上げいただきありがとうございます。',
  52.           '下記の内容にて納品させていただきます。',
  53.           'ご確認いただきますよう、お願いいたします。'
  54.         );
  55.  
  56.         $this->pdf  = new PDF_Japanese();
  57.  
  58.         // SJISフォント
  59.         $this->pdf->AddSJISFont();
  60.  
  61.         //ページ総数取得
  62.         $this->pdf->AliasNbPages();
  63.  
  64.         // マージン設定
  65.         $this->pdf->SetMargins(15, 20);
  66.  
  67.         // PDFを読み込んでページ数を取得
  68.         $pageno = $this->pdf->setSourceFile($this->tpl_pdf);
  69.         #$this->createPdf();
  70.     }
  71.  
  72.     function setData($arrData) {
  73.         $this->arrData = $arrData;
  74.  
  75.         // ページ番号よりIDを取得
  76.         $tplidx = $this->pdf->ImportPage(1);
  77.  
  78.         // ページを追加(新規)
  79.         $this->pdf->AddPage();
  80.  
  81.         //表示倍率(100%)
  82.         $this->pdf->SetDisplayMode($this->tpl_dispmode);
  83.  
  84.         if(SC_Utils_Ex::sfIsInt($arrData['order_id'])) {
  85.           $this->disp_mode = true;
  86.           $order_id = $arrData['order_id'];
  87.         }
  88.  
  89.         // テンプレート内容の位置、幅を調整 ※useTemplateに引数を与えなければ100%表示がデフォルト
  90.         $this->pdf->useTemplate($tplidx);
  91.  
  92.         $this->setShopData();
  93.         $this->setMessageData();
  94.         $this->setOrderData();
  95.         $this->setEtcData();
  96.  
  97.         //ロゴ画像
  98.         $logo_file = PDF_TEMPLATE_DIR . 'logo.png';
  99.         $this->pdf->Image($logo_file, 124, 46, 40);
  100.  
  101.     }
  102.  
  103.     function setShopData() {
  104.         // ショップ情報
  105.         $objInfo = new SC_SiteInfo();
  106.         $arrInfo = $objInfo->data;
  107.  
  108.         $this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B');          //ショップ名
  109.         $this->lfText(125, 63, $arrInfo['law_url'], 8);          //URL
  110.         $this->lfText(125, 68, $arrInfo['law_company'], 8);        //会社名
  111.         $text = "〒 ".$arrInfo['law_zip01']." - ".$arrInfo['law_zip02'];
  112.         $this->lfText(125, 71, $text, 8);  //郵便番号
  113.         $text = $this->arrPref[$arrInfo['law_pref']].$arrInfo['law_addr01'];
  114.         $this->lfText(125, 74, $text, 8);  //都道府県+住所1
  115.         $this->lfText(125, 77, $arrInfo['law_addr02'], 8);          //住所2
  116.         $text = "TEL: ".$arrInfo['law_tel01']."-".$arrInfo['law_tel02']."-".$arrInfo['law_tel03'];
  117.         //FAX番号が存在する場合、表示する
  118.         if (strlen($arrInfo['law_fax01']) > 0) {
  119.             $text .= " FAX: ".$arrInfo['law_fax01']."-".$arrInfo['law_fax02']."-".$arrInfo['law_fax03'];
  120.         }
  121.         $this->lfText(125, 80, $text, 8);  //TEL・FAX
  122.  
  123.         if (!empty($arrInfo['law_email'])) {
  124.             $text = "Email: ".$arrInfo['law_email'];
  125.             $this->lfText(125, 83, $text, 8);      //Email
  126.         }
  127.     }
  128.  
  129.     function setMessageData() {
  130.         // メッセージ
  131.         $this->lfText(27, 70, $this->arrData['msg1'], 8);  //メッセージ1
  132.         $this->lfText(27, 74, $this->arrData['msg2'], 8);  //メッセージ2
  133.         $this->lfText(27, 78, $this->arrData['msg3'], 8);  //メッセージ3
  134.         $text = "作成日: ".$this->arrData['year']."年".$this->arrData['month']."月".$this->arrData['day']."日";
  135.         $this->lfText(158, 288, $text, 8);  //作成日
  136.     }
  137.  
  138.     function setOrderData() {
  139.         // ショップ情報
  140.         $objInfo = new SC_SiteInfo();
  141.         $arrInfo = $objInfo->data;
  142.  
  143.         // DBから受注情報を読み込む
  144.         $this->lfGetOrderData($this->arrData['order_id']);
  145.  
  146.         // 購入者情報
  147.         $text = "〒 ".$this->arrDisp['order_zip01']." - ".$this->arrDisp['order_zip02'];
  148.         $this->lfText(23, 43, $text, 10); //購入者郵便番号
  149.         $text = $this->arrPref[$this->arrDisp['order_pref']] . $this->arrDisp['order_addr01'];
  150.         $this->lfText(27, 47, $text, 10); //購入者都道府県+住所1
  151.         $this->lfText(27, 51, $this->arrDisp['order_addr02'], 10); //購入者住所2
  152.         $text = $this->arrDisp['order_name01']." ".$this->arrDisp['order_name02']." 様";
  153.         $this->lfText(27, 59, $text, 11); //購入者氏名
  154.  
  155.         // お届け先情報
  156.         $this->pdf->SetFont('SJIS', '', 10);
  157.         $text = "〒 ".$this->arrDisp['deliv_zip01']." - ".$this->arrDisp['deliv_zip02'];
  158.         $this->lfText(22, 128, $text, 10); //お届け先郵便番号
  159.         $text = $this->arrPref[$this->arrDisp['deliv_pref']] . $this->arrDisp['deliv_addr01'];
  160.         $this->lfText(26, 132, $text, 10); //お届け先都道府県+住所1
  161.         $this->lfText(26, 136, $this->arrDisp['deliv_addr02'], 10); //お届け先住所2
  162.         $text = $this->arrDisp['deliv_name01']." ".$this->arrDisp['deliv_name02']." 様";
  163.         $this->lfText(26, 140, $text, 10); //お届け先氏名
  164.  
  165.         $this->lfText(144, 121, SC_Utils_Ex::sfDispDBDate($this->arrDisp['create_date']), 10); //ご注文日
  166.         $this->lfText(144, 131, $this->arrDisp['order_id'], 10); //注文番号
  167.  
  168.         $this->pdf->SetFont('SJIS', 'B', 15);
  169.         $this->pdf->Cell(0, 10, $this->sjis_conv($this->tpl_title), 0, 2, 'C', 0, '');  //文書タイトル(納品書・請求書)
  170.         $this->pdf->Cell(0, 66, '', 0, 2, 'R', 0, '');
  171.         $this->pdf->Cell(5, 0, '', 0, 0, 'R', 0, '');
  172.         $this->pdf->Cell(67, 8, $this->sjis_conv(number_format($this->arrDisp['payment_total'])." 円"), 0, 2, 'R', 0, '');
  173.         $this->pdf->Cell(0, 45, '', 0, 2, '', 0, '');
  174.  
  175.         $this->pdf->SetFont('SJIS', '', 8);
  176.  
  177.         $monetary_unit = $this->sjis_conv("円");
  178.         $point_unit = $this->sjis_conv("Pt");
  179.  
  180.         // 購入商品情報
  181.         for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) {
  182.  
  183.           // 購入数量
  184.           $data[0] = $this->arrDisp['quantity'][$i];
  185.  
  186.           // 税込金額(単価)
  187.           $data[1] = SC_Utils_Ex::sfPreTax($this->arrDisp['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']);
  188.  
  189.           // 小計(商品毎)
  190.           $data[2] = $data[0] * $data[1];
  191.  
  192.           $arrOrder[$i][0]  = $this->sjis_conv($this->arrDisp['product_name'][$i]." / ");
  193.           $arrOrder[$i][0] .= $this->sjis_conv($this->arrDisp['product_code'][$i]." / ");
  194.           if($this->arrDisp['classcategory_name1'][$i]) {
  195.             $arrOrder[$i][0] .= $this->sjis_conv(" [ ".$this->arrDisp['classcategory_name1'][$i]);
  196.             if($this->arrDisp['classcategory_name2'][$i] == "") {
  197.               $arrOrder[$i][0] .= " ]";
  198.             } else {
  199.               $arrOrder[$i][0] .= $this->sjis_conv(" * ".$this->arrDisp['classcategory_name2'][$i]." ]");
  200.             }
  201.           }
  202.           $arrOrder[$i][1]  = number_format($data[0]);
  203.           $arrOrder[$i][2]  = number_format($data[1]).$monetary_unit;
  204.           $arrOrder[$i][3]  = number_format($data[2]).$monetary_unit;
  205.  
  206.         }
  207.  
  208.         $arrOrder[$i][0] = "";
  209.         $arrOrder[$i][1] = "";
  210.         $arrOrder[$i][2] = "";
  211.         $arrOrder[$i][3] = "";
  212.  
  213.         $i++;
  214.         $arrOrder[$i][0] = "";
  215.         $arrOrder[$i][1] = "";
  216.         $arrOrder[$i][2] = $this->sjis_conv("商品合計");
  217.         $arrOrder[$i][3] = number_format($this->arrDisp['subtotal']).$monetary_unit;
  218.  
  219.         $i++;
  220.         $arrOrder[$i][0] = "";
  221.         $arrOrder[$i][1] = "";
  222.         $arrOrder[$i][2] = $this->sjis_conv("送料");
  223.         $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit;
  224.  
  225.         $i++;
  226.         $arrOrder[$i][0] = "";
  227.         $arrOrder[$i][1] = "";
  228.         $arrOrder[$i][2] = $this->sjis_conv("手数料");
  229.         $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit;
  230.  
  231.         $i++;
  232.         $arrOrder[$i][0] = "";
  233.         $arrOrder[$i][1] = "";
  234.         $arrOrder[$i][2] = $this->sjis_conv("値引き");
  235.         $arrOrder[$i][3] = "- ".number_format($this->arrDisp['use_point'] + $this->arrDisp['discount']).$monetary_unit;
  236.  
  237.         $i++;
  238.         $arrOrder[$i][0] = "";
  239.         $arrOrder[$i][1] = "";
  240.         $arrOrder[$i][2] = $this->sjis_conv("請求金額");
  241.         $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit;
  242.  
  243.         $i++;
  244.         $arrOrder[$i][0] = "";
  245.         $arrOrder[$i][1] = "";
  246.         $arrOrder[$i][2] = "";
  247.         $arrOrder[$i][3] = "";
  248.  
  249.         // ポイント表記
  250.         if ($this->arrData['disp_point'] && $this->arrDisp['customer_id']) {
  251.           $i++;
  252.           $arrOrder[$i][0] = "";
  253.           $arrOrder[$i][1] = "";
  254.           $arrOrder[$i][2] = $this->sjis_conv("利用ポイント");
  255.           $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit;
  256.  
  257.           $i++;
  258.           $arrOrder[$i][0] = "";
  259.           $arrOrder[$i][1] = "";
  260.           $arrOrder[$i][2] = $this->sjis_conv("加算ポイント");
  261.           $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit;
  262.  
  263.           $i++;
  264.           $arrOrder[$i][0] = "";
  265.           $arrOrder[$i][1] = "";
  266.           $arrOrder[$i][2] = $this->sjis_conv("所有ポイント");
  267.           $arrOrder[$i][3] = number_format($this->arrDisp['point']).$point_unit;
  268.         }
  269.  
  270.         $this->pdf->FancyTable($this->label_cell, $arrOrder, $this->width_cell);
  271.     }
  272.  
  273.     function setEtcData() {
  274.         $this->pdf->Cell(0, 10, '', 0, 1, 'C', 0, '');
  275.         $this->pdf->SetFont('SJIS', '', 9);
  276.         $this->pdf->MultiCell(0, 6, $this->sjis_conv("< 備 考 >"), 'T', 2, 'L', 0, '');  //備考
  277.         $this->pdf->Ln();
  278.         $this->pdf->SetFont('SJIS', '', 8);
  279.         $this->pdf->MultiCell(0, 4, $this->sjis_conv($this->arrData['etc1']."\n".$this->arrData['etc2']."\n".$this->arrData['etc3']), '', 2, 'L', 0, '');  //備考
  280.     }
  281.  
  282.     function createPdf() {
  283.         // PDFをブラウザに送信
  284.         if($this->pdf_download == 1) {
  285.           if ($this->pdf->PageNo() == 1) {
  286.             $filename = "nouhinsyo-No".$this->arrData['order_id'].".pdf";
  287.           } else {
  288.             $filename = "nouhinsyo.pdf";
  289.           }
  290.           $this->pdf->Output($this->sjis_conv($filename), D);
  291.         } else {
  292.           $this->pdf->Output();
  293.         }
  294.  
  295.         // 入力してPDFファイルを閉じる
  296.         $this->pdf->Close();
  297.     }
  298.  
  299.     // PDF_Japanese::Text へのパーサー
  300.     function lfText($x, $y, $text, $size, $style = '') {
  301.         $text = mb_convert_encoding($text, "SJIS", CHAR_CODE);
  302.  
  303.         $this->pdf->SetFont('SJIS', $style, $size);
  304.         $this->pdf->Text($x, $y, $text);
  305.     }
  306.  
  307.  
  308.     // 受注データの取得
  309.     function lfGetOrderData($order_id) {
  310.         if(SC_Utils_Ex::sfIsInt($order_id)) {
  311.             // DBから受注情報を読み込む
  312.             $objQuery = new SC_Query();
  313.             $where = "order_id = ?";
  314.             $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
  315.             #$objFormParam->setParam($arrRet[0]);
  316.             list($point, $total_point) = SC_Helper_DB_Ex::sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
  317.             #$objFormParam->setValue('total_point', $total_point);
  318.             #$objFormParam->setValue('point', $point);
  319.             $arrRet[0]['total_point'] = $total_point;
  320.             $arrRet[0]['point'] = $point;
  321.             $this->arrDisp = $arrRet[0];
  322.  
  323.             // 受注詳細データの取得
  324.             $arrRet = $this->lfGetOrderDetail($order_id);
  325.             $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
  326.             $this->arrDisp = array_merge($this->arrDisp, $arrRet);
  327.             #$objFormParam->setParam($arrRet);
  328.  
  329.             // その他支払い情報を表示
  330.             if($this->arrDisp["memo02"] != "") $this->arrDisp["payment_info"] = unserialize($this->arrDisp["memo02"]);
  331.             if($this->arrDisp["memo01"] == PAYMENT_CREDIT_ID){
  332.                   $this->arrDisp["payment_type"] = "クレジット決済";
  333.             } elseif ($this->arrDisp["memo01"] == PAYMENT_CONVENIENCE_ID) {
  334.                   $this->arrDisp["payment_type"] = "コンビニ決済";
  335.             } else {
  336.                   $this->arrDisp["payment_type"] = "お支払い";
  337.             }
  338.         }
  339.     }
  340.  
  341.     // 受注詳細データの取得
  342.     function lfGetOrderDetail($order_id) {
  343.       $objQuery = new SC_Query();
  344.       $col = "product_id, classcategory_id1, classcategory_id2, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate";
  345.       $where = "order_id = ?";
  346.       $objQuery->setorder("classcategory_id1, classcategory_id2");
  347.       $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id));
  348.       return $arrRet;
  349.     }
  350.  
  351.     // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJISのみ
  352.     function sjis_conv($conv_str) {
  353.       return (mb_convert_encoding($conv_str, "SJIS", CHAR_CODE));
  354.     }
  355.  
  356.  
  357. }
  358. ?>

Documentation generated on Tue, 28 Apr 2009 18:13:19 +0900 by phpDocumentor 1.4.2